package com.kgis.map.task.analysis
{
   import com.kgis.flexutil.RemoteService;
   import com.kgis.flexutil.ServiceUtil;
   import com.kgis.map.Map;
   import com.kgis.map.RemoteCaller;
   import com.kgis.map.geometry.IGeometry;
   import com.kgis.map.geometry.basetype.Extent;
   import com.kgis.map.layer.LayerData;

   import flash.external.ExternalInterface;
   import flash.net.getClassByAlias;
   import flash.net.registerClassAlias;
   import flash.utils.describeType;
   import flash.utils.getDefinitionByName;
   import flash.utils.getQualifiedClassName;

   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.rpc.AsyncResponder;
   import mx.rpc.AsyncToken;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   import com.kgis.map.task.analysis.SpatialAnalysis;

   /**
    * spatial analysis by sql
    */
   public class SpatialAnalysisBySql extends SpatialAnalysis {
      //分析sql
      private var _sql:String;

      private var _starttime:Date;

      public function SpatialAnalysisBySql(sql:String) {
         this._sql = sql;

         super("spatialQueryBySql");
      }

      override public function execute():void {
         if (null == onResult)
            return;
         _starttime = new Date();
         var remoteCaller:RemoteCaller = new RemoteCaller("spatialDataAnalyzeManagementService")
         var token:AsyncToken = remoteCaller.remoteObject.getOperation(operationName).send(sql);
         token.addResponder(new AsyncResponder(onAnalysisResult, onAnalysisFault));
      }

      /**根据图层id和geometries空间分析矢量设施数据*/
      private function onAnalysisResult(event:ResultEvent, token:Object = null):void {
         var features:ArrayCollection = event.result as ArrayCollection;
         trace("sql:" + sql + ",remote请求耗时:" + ((new Date()).getTime() - _starttime.getTime()).toString());
         onResult(features, token);
      }

      public function get sql():String
      {
         return _sql;
      }

      public function set sql(value:String):void
      {
         _sql = value;
      }


   }
}